package com.daxue.configtest.repository.remoteconfig;

import com.daxue.configtest.base.BaseEntity;
import com.daxue.configtest.domian.RemoteConfig;
import com.daxue.configtest.others.Entity;
import com.daxue.configtest.others.Nullable;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author daxue0929
 * @date 2023/3/11
 * @Entity 注解标注这是一个存储的实体类
 * rc: remote config的缩写。
 */

@Data
@EqualsAndHashCode(callSuper = true)
@Entity(
    table = com.daxue.configtest.repository.remoteconfig.dao.tables.Config.class,
    prefix = "rc"
)
public class ConfigEntity extends BaseEntity {

    private String env;
    private String name;
    private String app;

    @Nullable
    private String label;
    private String value;
    private String type;

    public static ConfigEntity convert(final RemoteConfig config) {
        ConfigEntity entity = new ConfigEntity();
        entity.setId(config.getId());
        entity.setEnv(config.getEnv());
        entity.setName(config.getName());
        entity.setApp(config.getApp());
        entity.setLabel(config.getLabel());
        entity.setValue(config.getValue());
        entity.setType(config.getType());
        return entity;
    }

    public RemoteConfig convert() {
        return RemoteConfig.newInstance()
            .setId(this.getId())
            .setCreatedOn(this.getCreatedOn())
            .setModifiedOn(this.getModifiedOn())
            .setEnv(this.getEnv())
            .setName(this.getName())
            .setApp(this.getApp())
            .setLabel(this.getLabel())
            .setValue(this.getValue())
            .setType(this.getType());
    }

}
